component  output="false" implements="CFIDE.ORM.IEventHandler"
{
public void function preLoad(any entity) {
 }
 
 public void function postLoad(any entity) {
 
 }
 
 public void function preInsert(any entity) {
 }
 
 public void function postInsert(any entity) { 
 	sendNotification( entity );
 }
 
 public void function preUpdate(any entity, struct oldData=structNew()) {
 }
 
 public void function postUpdate(any entity) {
 	sendNotification( entity );
 }
 
 public void function preDelete(any entity) {
 }
 
 public void function postDelete(any entity) {   
 }
 
 private void function sendNotification( entity )
 {
 	var info = getUpdateStruct( entity );
	
	sendGatewayMessage( "AtonementGateway", { 
		body = { 
			entityName = info.name, 
			id = info.id 
		} 
	} );
	
	writeLog( "sent notification for: " & info.name & " / " & info.id );
 }
 
 private string function getEntityName( any entity )
 {
 	var md = getMetadata( entity );
	
	if ( structKeyExists( md, "entityName" ) )
	{
		return md.entityName;
	}
	else
	{
		return listLast( md.name, ".");
	}
 }
 
 private struct function getUpdateStruct( entity )
 {
 	var entityName = getEntityName( entity );
 	var idPropName = ormGetSessionFactory().getIdentifierPropertyName( entityName );
	var idValue = evaluate( "entity.get#idPropName#()" );
	
	return {
		name = entityName,
		id = idValue
	};
 }
}